package com.ruoyi.system.api.factory;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.system.api.RemoteCustomerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/*远程客户服务降级处理 @iCAN*/
@Component
public class RemoteCustomerFallbackFactory implements FallbackFactory<RemoteCustomerService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteCustomerFallbackFactory.class);

    @Override
    public RemoteCustomerService create(Throwable throwable)
    {
        log.error("客户服务调用失败:{}", throwable.getMessage());
        return new RemoteCustomerService()
        {
            //@iCAN 测试触发fallbackFactory降级没生效。加了超时配置，1/0 超时都没触发。
            @Override
            public AjaxResult findCustomer(Integer id) {
                return AjaxResult.error("没找到客户");
            }
        };
    }
}
